import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
import format from '@dfeidao/atom-web/dt/format';
interface Par extends Event{
	page_no:number
}
export default async function a001(fd: IFeidaoAiBrowserComponent,e:Par) {
	// todo
	const res = await nodejs<{dt1:Array<{work_bill_no:string,job_content:string,cust_name:string,project_name:string,work_order_status:string,responsible:string,source_type:string,revisit_days:string,cust_sat:string}>;c:number}>('order-satisfaction/zj-000002/s001', { filter: { Pn:e.page_no} });
	for (let i = 0; i < res.dt1.length; i++) {
		if(res.dt1[i].source_type=="1"){
			res.dt1[i].source_type="总服务台";
		}else if(res.dt1[i].source_type=="2"){
			res.dt1[i].source_type="服务台";
	
		}else if(res.dt1[i].source_type=="3"){
			res.dt1[i].source_type="客户报障";
	
		}else{
			res.dt1[i].source_type="内部报障";
		}
	}
	
	const ret = Array();
	for (let i = 0; i < res.dt1.length; i++) {
		ret[i] = res.dt1[i].work_bill_no;
	}
	
	const rer=await nodejs<{dt1:Array<{work_bill_no:string,revisit_days:number,cust_sat:string}>;dt2:Array<{cust_sat:string}>}>("order-satisfaction/zj-000002/s002",{filter:{work_bill_no:ret}});
	const p=rer.dt1.map((n)=>{
		return {...n,revisit_days:format(n.revisit_days,2)}
	})
	const q = Array();
	for (let index = 0; index < res.dt1.length; index++) {
		for (let i = 0; i < rer.dt1.length; i++) {
			if (res.dt1[index].work_bill_no === rer.dt1[i].work_bill_no) {
				q[index] = {
					work_bill_no: res.dt1[index].work_bill_no, job_content: res.dt1[index].job_content, source_type: res.dt1[index].source_type,
					cust_name: res.dt1[index].cust_name, project_name: res.dt1[index].project_name, work_order_status: res.dt1[index].work_order_status,
					responsible: res.dt1[index].responsible, revisit_days: p[index].revisit_days,cust_sat: p[i].cust_sat
				};

			}
		}
	}
	for (let i = 0; i < q.length; i++) {
		if(q[i].cust_sat=="1"){
			q[i].cust_sat="非常满意";
		}else if(q[i].cust_sat=="2"){
			q[i].cust_sat="满意";
	
		}else if(q[i].cust_sat=="3"){
			q[i].cust_sat="一般";
	
		}else if(q[i].cust_sat=="4"){
			q[i].cust_sat="不满意";
		}else{
			q[i].cust_sat="未回访";

		}
	}
	if(res.dt1.length>0){
		render(fd,q,p001,'p001','inner');
	}else{
		render(fd,"",p002,'p002','inner');
	}
	}
